
USE [HRB]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbAdvs table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_Get_List

AS


				
				SELECT
					[AdvID],
					[Path],
					[Tooltip],
					[LinkPage],
					[Index]
				FROM
					[dbo].[hrbAdvs]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbAdvs table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[AdvID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [AdvID]'
				SET @SQL = @SQL + ', [Path]'
				SET @SQL = @SQL + ', [Tooltip]'
				SET @SQL = @SQL + ', [LinkPage]'
				SET @SQL = @SQL + ', [Index]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbAdvs]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [AdvID],'
				SET @SQL = @SQL + ' [Path],'
				SET @SQL = @SQL + ' [Tooltip],'
				SET @SQL = @SQL + ' [LinkPage],'
				SET @SQL = @SQL + ' [Index]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbAdvs]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbAdvs table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_Insert
(

	@AdvId int    OUTPUT,

	@Path nvarchar (1000)  ,

	@Tooltip nvarchar (1000)  ,

	@LinkPage nvarchar (1000)  ,

	@Index int   
)
AS


				
				INSERT INTO [dbo].[hrbAdvs]
					(
					[Path]
					,[Tooltip]
					,[LinkPage]
					,[Index]
					)
				VALUES
					(
					@Path
					,@Tooltip
					,@LinkPage
					,@Index
					)
				
				-- Get the identity value
				SET @AdvId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbAdvs table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_Update
(

	@AdvId int   ,

	@Path nvarchar (1000)  ,

	@Tooltip nvarchar (1000)  ,

	@LinkPage nvarchar (1000)  ,

	@Index int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbAdvs]
				SET
					[Path] = @Path
					,[Tooltip] = @Tooltip
					,[LinkPage] = @LinkPage
					,[Index] = @Index
				WHERE
[AdvID] = @AdvId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbAdvs table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_Delete
(

	@AdvId int   
)
AS


				DELETE FROM [dbo].[hrbAdvs] WITH (ROWLOCK) 
				WHERE
					[AdvID] = @AdvId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_GetByAdvId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_GetByAdvId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_GetByAdvId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbAdvs table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_GetByAdvId
(

	@AdvId int   
)
AS


				SELECT
					[AdvID],
					[Path],
					[Tooltip],
					[LinkPage],
					[Index]
				FROM
					[dbo].[hrbAdvs]
				WHERE
					[AdvID] = @AdvId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbAdvs_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbAdvs_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbAdvs_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbAdvs table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbAdvs_Find
(

	@SearchUsingOR bit   = null ,

	@AdvId int   = null ,

	@Path nvarchar (1000)  = null ,

	@Tooltip nvarchar (1000)  = null ,

	@LinkPage nvarchar (1000)  = null ,

	@Index int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [AdvID]
	, [Path]
	, [Tooltip]
	, [LinkPage]
	, [Index]
    FROM
	[dbo].[hrbAdvs]
    WHERE 
	 ([AdvID] = @AdvId OR @AdvId IS NULL)
	AND ([Path] = @Path OR @Path IS NULL)
	AND ([Tooltip] = @Tooltip OR @Tooltip IS NULL)
	AND ([LinkPage] = @LinkPage OR @LinkPage IS NULL)
	AND ([Index] = @Index OR @Index IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [AdvID]
	, [Path]
	, [Tooltip]
	, [LinkPage]
	, [Index]
    FROM
	[dbo].[hrbAdvs]
    WHERE 
	 ([AdvID] = @AdvId AND @AdvId is not null)
	OR ([Path] = @Path AND @Path is not null)
	OR ([Tooltip] = @Tooltip AND @Tooltip is not null)
	OR ([LinkPage] = @LinkPage AND @LinkPage is not null)
	OR ([Index] = @Index AND @Index is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbCategoryDisplay table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_Get_List

AS


				
				SELECT
					[CategoryID],
					[IsShowMenu],
					[IsShowCategory],
					[Index],
					[LanguageID]
				FROM
					[dbo].[hrbCategoryDisplay]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbCategoryDisplay table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[CategoryID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [CategoryID]'
				SET @SQL = @SQL + ', [IsShowMenu]'
				SET @SQL = @SQL + ', [IsShowCategory]'
				SET @SQL = @SQL + ', [Index]'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbCategoryDisplay]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [CategoryID],'
				SET @SQL = @SQL + ' [IsShowMenu],'
				SET @SQL = @SQL + ' [IsShowCategory],'
				SET @SQL = @SQL + ' [Index],'
				SET @SQL = @SQL + ' [LanguageID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbCategoryDisplay]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbCategoryDisplay table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_Insert
(

	@CategoryId uniqueidentifier   ,

	@IsShowMenu bit   ,

	@IsShowCategory bigint   ,

	@Index int   ,

	@LanguageId int   
)
AS


				
				INSERT INTO [dbo].[hrbCategoryDisplay]
					(
					[CategoryID]
					,[IsShowMenu]
					,[IsShowCategory]
					,[Index]
					,[LanguageID]
					)
				VALUES
					(
					@CategoryId
					,@IsShowMenu
					,@IsShowCategory
					,@Index
					,@LanguageId
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbCategoryDisplay table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_Update
(

	@CategoryId uniqueidentifier   ,

	@OriginalCategoryId uniqueidentifier   ,

	@IsShowMenu bit   ,

	@IsShowCategory bigint   ,

	@Index int   ,

	@LanguageId int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbCategoryDisplay]
				SET
					[CategoryID] = @CategoryId
					,[IsShowMenu] = @IsShowMenu
					,[IsShowCategory] = @IsShowCategory
					,[Index] = @Index
					,[LanguageID] = @LanguageId
				WHERE
[CategoryID] = @OriginalCategoryId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbCategoryDisplay table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_Delete
(

	@CategoryId uniqueidentifier   
)
AS


				DELETE FROM [dbo].[hrbCategoryDisplay] WITH (ROWLOCK) 
				WHERE
					[CategoryID] = @CategoryId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_GetByCategoryIdLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_GetByCategoryIdLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_GetByCategoryIdLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbCategoryDisplay table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_GetByCategoryIdLanguageId
(

	@CategoryId uniqueidentifier   ,

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[CategoryID],
					[IsShowMenu],
					[IsShowCategory],
					[Index],
					[LanguageID]
				FROM
					[dbo].[hrbCategoryDisplay]
				WHERE
					[CategoryID] = @CategoryId
					AND [LanguageID] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_GetByCategoryId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_GetByCategoryId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_GetByCategoryId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbCategoryDisplay table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_GetByCategoryId
(

	@CategoryId uniqueidentifier   
)
AS


				SELECT
					[CategoryID],
					[IsShowMenu],
					[IsShowCategory],
					[Index],
					[LanguageID]
				FROM
					[dbo].[hrbCategoryDisplay]
				WHERE
					[CategoryID] = @CategoryId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategoryDisplay_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategoryDisplay_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategoryDisplay_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbCategoryDisplay table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategoryDisplay_Find
(

	@SearchUsingOR bit   = null ,

	@CategoryId uniqueidentifier   = null ,

	@IsShowMenu bit   = null ,

	@IsShowCategory bigint   = null ,

	@Index int   = null ,

	@LanguageId int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [CategoryID]
	, [IsShowMenu]
	, [IsShowCategory]
	, [Index]
	, [LanguageID]
    FROM
	[dbo].[hrbCategoryDisplay]
    WHERE 
	 ([CategoryID] = @CategoryId OR @CategoryId IS NULL)
	AND ([IsShowMenu] = @IsShowMenu OR @IsShowMenu IS NULL)
	AND ([IsShowCategory] = @IsShowCategory OR @IsShowCategory IS NULL)
	AND ([Index] = @Index OR @Index IS NULL)
	AND ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [CategoryID]
	, [IsShowMenu]
	, [IsShowCategory]
	, [Index]
	, [LanguageID]
    FROM
	[dbo].[hrbCategoryDisplay]
    WHERE 
	 ([CategoryID] = @CategoryId AND @CategoryId is not null)
	OR ([IsShowMenu] = @IsShowMenu AND @IsShowMenu is not null)
	OR ([IsShowCategory] = @IsShowCategory AND @IsShowCategory is not null)
	OR ([Index] = @Index AND @Index is not null)
	OR ([LanguageID] = @LanguageId AND @LanguageId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbEvents table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_Get_List

AS


				
				SELECT
					[EventID],
					[Title],
					[Description],
					[LanguageID],
					[DateCreated],
					[DateModified],
					[IsPublished]
				FROM
					[dbo].[hrbEvents]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbEvents table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[EventID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [EventID]'
				SET @SQL = @SQL + ', [Title]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [IsPublished]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbEvents]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [EventID],'
				SET @SQL = @SQL + ' [Title],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [LanguageID],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [IsPublished]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbEvents]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbEvents table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_Insert
(

	@EventId uniqueidentifier   ,

	@Title nvarchar (255)  ,

	@Description nvarchar (4000)  ,

	@LanguageId int   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IsPublished bit   
)
AS


				
				INSERT INTO [dbo].[hrbEvents]
					(
					[EventID]
					,[Title]
					,[Description]
					,[LanguageID]
					,[DateCreated]
					,[DateModified]
					,[IsPublished]
					)
				VALUES
					(
					@EventId
					,@Title
					,@Description
					,@LanguageId
					,@DateCreated
					,@DateModified
					,@IsPublished
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbEvents table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_Update
(

	@EventId uniqueidentifier   ,

	@OriginalEventId uniqueidentifier   ,

	@Title nvarchar (255)  ,

	@Description nvarchar (4000)  ,

	@LanguageId int   ,

	@OriginalLanguageId int   ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IsPublished bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbEvents]
				SET
					[EventID] = @EventId
					,[Title] = @Title
					,[Description] = @Description
					,[LanguageID] = @LanguageId
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[IsPublished] = @IsPublished
				WHERE
[EventID] = @OriginalEventId 
AND [LanguageID] = @OriginalLanguageId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbEvents table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_Delete
(

	@EventId uniqueidentifier   ,

	@LanguageId int   
)
AS


				DELETE FROM [dbo].[hrbEvents] WITH (ROWLOCK) 
				WHERE
					[EventID] = @EventId
					AND [LanguageID] = @LanguageId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbEvents table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[EventID],
					[Title],
					[Description],
					[LanguageID],
					[DateCreated],
					[DateModified],
					[IsPublished]
				FROM
					[dbo].[hrbEvents]
				WHERE
					[LanguageID] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_GetByEventIdLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_GetByEventIdLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_GetByEventIdLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbEvents table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_GetByEventIdLanguageId
(

	@EventId uniqueidentifier   ,

	@LanguageId int   
)
AS


				SELECT
					[EventID],
					[Title],
					[Description],
					[LanguageID],
					[DateCreated],
					[DateModified],
					[IsPublished]
				FROM
					[dbo].[hrbEvents]
				WHERE
					[EventID] = @EventId
					AND [LanguageID] = @LanguageId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbEvents_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbEvents_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbEvents_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbEvents table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbEvents_Find
(

	@SearchUsingOR bit   = null ,

	@EventId uniqueidentifier   = null ,

	@Title nvarchar (255)  = null ,

	@Description nvarchar (4000)  = null ,

	@LanguageId int   = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@IsPublished bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [EventID]
	, [Title]
	, [Description]
	, [LanguageID]
	, [DateCreated]
	, [DateModified]
	, [IsPublished]
    FROM
	[dbo].[hrbEvents]
    WHERE 
	 ([EventID] = @EventId OR @EventId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
	AND ([DateCreated] = @DateCreated OR @DateCreated IS NULL)
	AND ([DateModified] = @DateModified OR @DateModified IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [EventID]
	, [Title]
	, [Description]
	, [LanguageID]
	, [DateCreated]
	, [DateModified]
	, [IsPublished]
    FROM
	[dbo].[hrbEvents]
    WHERE 
	 ([EventID] = @EventId AND @EventId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([LanguageID] = @LanguageId AND @LanguageId is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbPosts table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_Get_List

AS


				
				SELECT
					[PostID],
					[Title],
					[ImagePath],
					[Description],
					[PostContent],
					[DateCreated],
					[DateModified],
					[Author],
					[IsPublished],
					[Slug],
					[Phone],
					[Email],
					[Address],
					[IsCommentAllowed],
					[AttachedPath]
				FROM
					[dbo].[hrbPosts]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbPosts table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[PostID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [PostID]'
				SET @SQL = @SQL + ', [Title]'
				SET @SQL = @SQL + ', [ImagePath]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [PostContent]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [Author]'
				SET @SQL = @SQL + ', [IsPublished]'
				SET @SQL = @SQL + ', [Slug]'
				SET @SQL = @SQL + ', [Phone]'
				SET @SQL = @SQL + ', [Email]'
				SET @SQL = @SQL + ', [Address]'
				SET @SQL = @SQL + ', [IsCommentAllowed]'
				SET @SQL = @SQL + ', [AttachedPath]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPosts]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [PostID],'
				SET @SQL = @SQL + ' [Title],'
				SET @SQL = @SQL + ' [ImagePath],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [PostContent],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [Author],'
				SET @SQL = @SQL + ' [IsPublished],'
				SET @SQL = @SQL + ' [Slug],'
				SET @SQL = @SQL + ' [Phone],'
				SET @SQL = @SQL + ' [Email],'
				SET @SQL = @SQL + ' [Address],'
				SET @SQL = @SQL + ' [IsCommentAllowed],'
				SET @SQL = @SQL + ' [AttachedPath]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPosts]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbPosts table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_Insert
(

	@PostId uniqueidentifier   ,

	@Title nvarchar (255)  ,

	@ImagePath nvarchar (1000)  ,

	@Description nvarchar (1000)  ,

	@PostContent nvarchar (MAX)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@Author nvarchar (255)  ,

	@IsPublished bit   ,

	@Slug nvarchar (255)  ,

	@Phone nvarchar (50)  ,

	@Email nvarchar (50)  ,

	@Address nvarchar (100)  ,

	@IsCommentAllowed bit   ,

	@AttachedPath nvarchar (1000)  
)
AS


				
				INSERT INTO [dbo].[hrbPosts]
					(
					[PostID]
					,[Title]
					,[ImagePath]
					,[Description]
					,[PostContent]
					,[DateCreated]
					,[DateModified]
					,[Author]
					,[IsPublished]
					,[Slug]
					,[Phone]
					,[Email]
					,[Address]
					,[IsCommentAllowed]
					,[AttachedPath]
					)
				VALUES
					(
					@PostId
					,@Title
					,@ImagePath
					,@Description
					,@PostContent
					,@DateCreated
					,@DateModified
					,@Author
					,@IsPublished
					,@Slug
					,@Phone
					,@Email
					,@Address
					,@IsCommentAllowed
					,@AttachedPath
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbPosts table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_Update
(

	@PostId uniqueidentifier   ,

	@OriginalPostId uniqueidentifier   ,

	@Title nvarchar (255)  ,

	@ImagePath nvarchar (1000)  ,

	@Description nvarchar (1000)  ,

	@PostContent nvarchar (MAX)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@Author nvarchar (255)  ,

	@IsPublished bit   ,

	@Slug nvarchar (255)  ,

	@Phone nvarchar (50)  ,

	@Email nvarchar (50)  ,

	@Address nvarchar (100)  ,

	@IsCommentAllowed bit   ,

	@AttachedPath nvarchar (1000)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbPosts]
				SET
					[PostID] = @PostId
					,[Title] = @Title
					,[ImagePath] = @ImagePath
					,[Description] = @Description
					,[PostContent] = @PostContent
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[Author] = @Author
					,[IsPublished] = @IsPublished
					,[Slug] = @Slug
					,[Phone] = @Phone
					,[Email] = @Email
					,[Address] = @Address
					,[IsCommentAllowed] = @IsCommentAllowed
					,[AttachedPath] = @AttachedPath
				WHERE
[PostID] = @OriginalPostId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbPosts table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_Delete
(

	@PostId uniqueidentifier   
)
AS


				DELETE FROM [dbo].[hrbPosts] WITH (ROWLOCK) 
				WHERE
					[PostID] = @PostId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_GetByPostId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_GetByPostId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_GetByPostId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPosts table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_GetByPostId
(

	@PostId uniqueidentifier   
)
AS


				SELECT
					[PostID],
					[Title],
					[ImagePath],
					[Description],
					[PostContent],
					[DateCreated],
					[DateModified],
					[Author],
					[IsPublished],
					[Slug],
					[Phone],
					[Email],
					[Address],
					[IsCommentAllowed],
					[AttachedPath]
				FROM
					[dbo].[hrbPosts]
				WHERE
					[PostID] = @PostId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPosts_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPosts_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPosts_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbPosts table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPosts_Find
(

	@SearchUsingOR bit   = null ,

	@PostId uniqueidentifier   = null ,

	@Title nvarchar (255)  = null ,

	@ImagePath nvarchar (1000)  = null ,

	@Description nvarchar (1000)  = null ,

	@PostContent nvarchar (MAX)  = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@Author nvarchar (255)  = null ,

	@IsPublished bit   = null ,

	@Slug nvarchar (255)  = null ,

	@Phone nvarchar (50)  = null ,

	@Email nvarchar (50)  = null ,

	@Address nvarchar (100)  = null ,

	@IsCommentAllowed bit   = null ,

	@AttachedPath nvarchar (1000)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [PostID]
	, [Title]
	, [ImagePath]
	, [Description]
	, [PostContent]
	, [DateCreated]
	, [DateModified]
	, [Author]
	, [IsPublished]
	, [Slug]
	, [Phone]
	, [Email]
	, [Address]
	, [IsCommentAllowed]
	, [AttachedPath]
    FROM
	[dbo].[hrbPosts]
    WHERE 
	 ([PostID] = @PostId OR @PostId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([ImagePath] = @ImagePath OR @ImagePath IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([PostContent] = @PostContent OR @PostContent IS NULL)
	AND ([DateCreated] = @DateCreated OR @DateCreated IS NULL)
	AND ([DateModified] = @DateModified OR @DateModified IS NULL)
	AND ([Author] = @Author OR @Author IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([Slug] = @Slug OR @Slug IS NULL)
	AND ([Phone] = @Phone OR @Phone IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Address] = @Address OR @Address IS NULL)
	AND ([IsCommentAllowed] = @IsCommentAllowed OR @IsCommentAllowed IS NULL)
	AND ([AttachedPath] = @AttachedPath OR @AttachedPath IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [PostID]
	, [Title]
	, [ImagePath]
	, [Description]
	, [PostContent]
	, [DateCreated]
	, [DateModified]
	, [Author]
	, [IsPublished]
	, [Slug]
	, [Phone]
	, [Email]
	, [Address]
	, [IsCommentAllowed]
	, [AttachedPath]
    FROM
	[dbo].[hrbPosts]
    WHERE 
	 ([PostID] = @PostId AND @PostId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([ImagePath] = @ImagePath AND @ImagePath is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([PostContent] = @PostContent AND @PostContent is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([Author] = @Author AND @Author is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([Slug] = @Slug AND @Slug is not null)
	OR ([Phone] = @Phone AND @Phone is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Address] = @Address AND @Address is not null)
	OR ([IsCommentAllowed] = @IsCommentAllowed AND @IsCommentAllowed is not null)
	OR ([AttachedPath] = @AttachedPath AND @AttachedPath is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbLanguages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_Get_List

AS


				
				SELECT
					[LanguageID],
					[Name],
					[Code],
					[IsActive]
				FROM
					[dbo].[hrbLanguages]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbLanguages table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[LanguageID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ', [Name]'
				SET @SQL = @SQL + ', [Code]'
				SET @SQL = @SQL + ', [IsActive]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbLanguages]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [LanguageID],'
				SET @SQL = @SQL + ' [Name],'
				SET @SQL = @SQL + ' [Code],'
				SET @SQL = @SQL + ' [IsActive]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbLanguages]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbLanguages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_Insert
(

	@LanguageId int    OUTPUT,

	@Name nvarchar (100)  ,

	@Code nvarchar (50)  ,

	@IsActive bit   
)
AS


				
				INSERT INTO [dbo].[hrbLanguages]
					(
					[Name]
					,[Code]
					,[IsActive]
					)
				VALUES
					(
					@Name
					,@Code
					,@IsActive
					)
				
				-- Get the identity value
				SET @LanguageId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbLanguages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_Update
(

	@LanguageId int   ,

	@Name nvarchar (100)  ,

	@Code nvarchar (50)  ,

	@IsActive bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbLanguages]
				SET
					[Name] = @Name
					,[Code] = @Code
					,[IsActive] = @IsActive
				WHERE
[LanguageID] = @LanguageId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbLanguages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_Delete
(

	@LanguageId int   
)
AS


				DELETE FROM [dbo].[hrbLanguages] WITH (ROWLOCK) 
				WHERE
					[LanguageID] = @LanguageId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbLanguages table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_GetByLanguageId
(

	@LanguageId int   
)
AS


				SELECT
					[LanguageID],
					[Name],
					[Code],
					[IsActive]
				FROM
					[dbo].[hrbLanguages]
				WHERE
					[LanguageID] = @LanguageId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbLanguages_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbLanguages_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbLanguages_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbLanguages table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbLanguages_Find
(

	@SearchUsingOR bit   = null ,

	@LanguageId int   = null ,

	@Name nvarchar (100)  = null ,

	@Code nvarchar (50)  = null ,

	@IsActive bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [LanguageID]
	, [Name]
	, [Code]
	, [IsActive]
    FROM
	[dbo].[hrbLanguages]
    WHERE 
	 ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
	AND ([Name] = @Name OR @Name IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([IsActive] = @IsActive OR @IsActive IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [LanguageID]
	, [Name]
	, [Code]
	, [IsActive]
    FROM
	[dbo].[hrbLanguages]
    WHERE 
	 ([LanguageID] = @LanguageId AND @LanguageId is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([IsActive] = @IsActive AND @IsActive is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbImages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_Get_List

AS


				
				SELECT
					[ImageID],
					[Path],
					[Title],
					[Description],
					[LinkPage],
					[EventID],
					[LanguageID]
				FROM
					[dbo].[hrbImages]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbImages table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[ImageID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [ImageID]'
				SET @SQL = @SQL + ', [Path]'
				SET @SQL = @SQL + ', [Title]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [LinkPage]'
				SET @SQL = @SQL + ', [EventID]'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbImages]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [ImageID],'
				SET @SQL = @SQL + ' [Path],'
				SET @SQL = @SQL + ' [Title],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [LinkPage],'
				SET @SQL = @SQL + ' [EventID],'
				SET @SQL = @SQL + ' [LanguageID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbImages]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbImages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_Insert
(

	@ImageId int    OUTPUT,

	@Path nvarchar (1000)  ,

	@Title nvarchar (255)  ,

	@Description nvarchar (4000)  ,

	@LinkPage nvarchar (1000)  ,

	@EventId uniqueidentifier   ,

	@LanguageId int   
)
AS


				
				INSERT INTO [dbo].[hrbImages]
					(
					[Path]
					,[Title]
					,[Description]
					,[LinkPage]
					,[EventID]
					,[LanguageID]
					)
				VALUES
					(
					@Path
					,@Title
					,@Description
					,@LinkPage
					,@EventId
					,@LanguageId
					)
				
				-- Get the identity value
				SET @ImageId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbImages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_Update
(

	@ImageId int   ,

	@Path nvarchar (1000)  ,

	@Title nvarchar (255)  ,

	@Description nvarchar (4000)  ,

	@LinkPage nvarchar (1000)  ,

	@EventId uniqueidentifier   ,

	@LanguageId int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbImages]
				SET
					[Path] = @Path
					,[Title] = @Title
					,[Description] = @Description
					,[LinkPage] = @LinkPage
					,[EventID] = @EventId
					,[LanguageID] = @LanguageId
				WHERE
[ImageID] = @ImageId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbImages table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_Delete
(

	@ImageId int   
)
AS


				DELETE FROM [dbo].[hrbImages] WITH (ROWLOCK) 
				WHERE
					[ImageID] = @ImageId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_GetByEventIdLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_GetByEventIdLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_GetByEventIdLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbImages table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_GetByEventIdLanguageId
(

	@EventId uniqueidentifier   ,

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[ImageID],
					[Path],
					[Title],
					[Description],
					[LinkPage],
					[EventID],
					[LanguageID]
				FROM
					[dbo].[hrbImages]
				WHERE
					[EventID] = @EventId
					AND [LanguageID] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_GetByImageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_GetByImageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_GetByImageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbImages table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_GetByImageId
(

	@ImageId int   
)
AS


				SELECT
					[ImageID],
					[Path],
					[Title],
					[Description],
					[LinkPage],
					[EventID],
					[LanguageID]
				FROM
					[dbo].[hrbImages]
				WHERE
					[ImageID] = @ImageId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbImages_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbImages_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbImages_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbImages table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbImages_Find
(

	@SearchUsingOR bit   = null ,

	@ImageId int   = null ,

	@Path nvarchar (1000)  = null ,

	@Title nvarchar (255)  = null ,

	@Description nvarchar (4000)  = null ,

	@LinkPage nvarchar (1000)  = null ,

	@EventId uniqueidentifier   = null ,

	@LanguageId int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ImageID]
	, [Path]
	, [Title]
	, [Description]
	, [LinkPage]
	, [EventID]
	, [LanguageID]
    FROM
	[dbo].[hrbImages]
    WHERE 
	 ([ImageID] = @ImageId OR @ImageId IS NULL)
	AND ([Path] = @Path OR @Path IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([LinkPage] = @LinkPage OR @LinkPage IS NULL)
	AND ([EventID] = @EventId OR @EventId IS NULL)
	AND ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ImageID]
	, [Path]
	, [Title]
	, [Description]
	, [LinkPage]
	, [EventID]
	, [LanguageID]
    FROM
	[dbo].[hrbImages]
    WHERE 
	 ([ImageID] = @ImageId AND @ImageId is not null)
	OR ([Path] = @Path AND @Path is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([LinkPage] = @LinkPage AND @LinkPage is not null)
	OR ([EventID] = @EventId AND @EventId is not null)
	OR ([LanguageID] = @LanguageId AND @LanguageId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbCategories table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_Get_List

AS


				
				SELECT
					[CategoryID],
					[CategoryName],
					[Description],
					[ParentID],
					[LanguageID]
				FROM
					[dbo].[hrbCategories]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbCategories table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[CategoryID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [CategoryID]'
				SET @SQL = @SQL + ', [CategoryName]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [ParentID]'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbCategories]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [CategoryID],'
				SET @SQL = @SQL + ' [CategoryName],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [ParentID],'
				SET @SQL = @SQL + ' [LanguageID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbCategories]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbCategories table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_Insert
(

	@CategoryId uniqueidentifier   ,

	@CategoryName nvarchar (255)  ,

	@Description nvarchar (255)  ,

	@ParentId uniqueidentifier   ,

	@LanguageId int   
)
AS


				
				INSERT INTO [dbo].[hrbCategories]
					(
					[CategoryID]
					,[CategoryName]
					,[Description]
					,[ParentID]
					,[LanguageID]
					)
				VALUES
					(
					@CategoryId
					,@CategoryName
					,@Description
					,@ParentId
					,@LanguageId
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbCategories table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_Update
(

	@CategoryId uniqueidentifier   ,

	@OriginalCategoryId uniqueidentifier   ,

	@CategoryName nvarchar (255)  ,

	@Description nvarchar (255)  ,

	@ParentId uniqueidentifier   ,

	@LanguageId int   ,

	@OriginalLanguageId int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbCategories]
				SET
					[CategoryID] = @CategoryId
					,[CategoryName] = @CategoryName
					,[Description] = @Description
					,[ParentID] = @ParentId
					,[LanguageID] = @LanguageId
				WHERE
[CategoryID] = @OriginalCategoryId 
AND [LanguageID] = @OriginalLanguageId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbCategories table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_Delete
(

	@CategoryId uniqueidentifier   ,

	@LanguageId int   
)
AS


				DELETE FROM [dbo].[hrbCategories] WITH (ROWLOCK) 
				WHERE
					[CategoryID] = @CategoryId
					AND [LanguageID] = @LanguageId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbCategories table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[CategoryID],
					[CategoryName],
					[Description],
					[ParentID],
					[LanguageID]
				FROM
					[dbo].[hrbCategories]
				WHERE
					[LanguageID] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_GetByCategoryIdLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_GetByCategoryIdLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_GetByCategoryIdLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbCategories table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_GetByCategoryIdLanguageId
(

	@CategoryId uniqueidentifier   ,

	@LanguageId int   
)
AS


				SELECT
					[CategoryID],
					[CategoryName],
					[Description],
					[ParentID],
					[LanguageID]
				FROM
					[dbo].[hrbCategories]
				WHERE
					[CategoryID] = @CategoryId
					AND [LanguageID] = @LanguageId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbCategories_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbCategories_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbCategories_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbCategories table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbCategories_Find
(

	@SearchUsingOR bit   = null ,

	@CategoryId uniqueidentifier   = null ,

	@CategoryName nvarchar (255)  = null ,

	@Description nvarchar (255)  = null ,

	@ParentId uniqueidentifier   = null ,

	@LanguageId int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [CategoryID]
	, [CategoryName]
	, [Description]
	, [ParentID]
	, [LanguageID]
    FROM
	[dbo].[hrbCategories]
    WHERE 
	 ([CategoryID] = @CategoryId OR @CategoryId IS NULL)
	AND ([CategoryName] = @CategoryName OR @CategoryName IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([ParentID] = @ParentId OR @ParentId IS NULL)
	AND ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [CategoryID]
	, [CategoryName]
	, [Description]
	, [ParentID]
	, [LanguageID]
    FROM
	[dbo].[hrbCategories]
    WHERE 
	 ([CategoryID] = @CategoryId AND @CategoryId is not null)
	OR ([CategoryName] = @CategoryName AND @CategoryName is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([ParentID] = @ParentId AND @ParentId is not null)
	OR ([LanguageID] = @LanguageId AND @LanguageId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbPage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_Get_List

AS


				
				SELECT
					[PageID],
					[Title],
					[Description],
					[PageContent],
					[Keywords],
					[DateCreated],
					[DateModified],
					[IsPublished],
					[LanguageID],
					[ParentID],
					[Slug],
					[AttachedPath]
				FROM
					[dbo].[hrbPage]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbPage table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[PageID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [PageID]'
				SET @SQL = @SQL + ', [Title]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [PageContent]'
				SET @SQL = @SQL + ', [Keywords]'
				SET @SQL = @SQL + ', [DateCreated]'
				SET @SQL = @SQL + ', [DateModified]'
				SET @SQL = @SQL + ', [IsPublished]'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ', [ParentID]'
				SET @SQL = @SQL + ', [Slug]'
				SET @SQL = @SQL + ', [AttachedPath]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPage]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [PageID],'
				SET @SQL = @SQL + ' [Title],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [PageContent],'
				SET @SQL = @SQL + ' [Keywords],'
				SET @SQL = @SQL + ' [DateCreated],'
				SET @SQL = @SQL + ' [DateModified],'
				SET @SQL = @SQL + ' [IsPublished],'
				SET @SQL = @SQL + ' [LanguageID],'
				SET @SQL = @SQL + ' [ParentID],'
				SET @SQL = @SQL + ' [Slug],'
				SET @SQL = @SQL + ' [AttachedPath]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPage]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbPage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_Insert
(

	@PageId uniqueidentifier   ,

	@Title nvarchar (255)  ,

	@Description nvarchar (1000)  ,

	@PageContent nvarchar (MAX)  ,

	@Keywords nvarchar (4000)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IsPublished bit   ,

	@LanguageId int   ,

	@ParentId uniqueidentifier   ,

	@Slug nvarchar (255)  ,

	@AttachedPath nvarchar (1000)  
)
AS


				
				INSERT INTO [dbo].[hrbPage]
					(
					[PageID]
					,[Title]
					,[Description]
					,[PageContent]
					,[Keywords]
					,[DateCreated]
					,[DateModified]
					,[IsPublished]
					,[LanguageID]
					,[ParentID]
					,[Slug]
					,[AttachedPath]
					)
				VALUES
					(
					@PageId
					,@Title
					,@Description
					,@PageContent
					,@Keywords
					,@DateCreated
					,@DateModified
					,@IsPublished
					,@LanguageId
					,@ParentId
					,@Slug
					,@AttachedPath
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbPage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_Update
(

	@PageId uniqueidentifier   ,

	@OriginalPageId uniqueidentifier   ,

	@Title nvarchar (255)  ,

	@Description nvarchar (1000)  ,

	@PageContent nvarchar (MAX)  ,

	@Keywords nvarchar (4000)  ,

	@DateCreated datetime   ,

	@DateModified datetime   ,

	@IsPublished bit   ,

	@LanguageId int   ,

	@OriginalLanguageId int   ,

	@ParentId uniqueidentifier   ,

	@Slug nvarchar (255)  ,

	@AttachedPath nvarchar (1000)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbPage]
				SET
					[PageID] = @PageId
					,[Title] = @Title
					,[Description] = @Description
					,[PageContent] = @PageContent
					,[Keywords] = @Keywords
					,[DateCreated] = @DateCreated
					,[DateModified] = @DateModified
					,[IsPublished] = @IsPublished
					,[LanguageID] = @LanguageId
					,[ParentID] = @ParentId
					,[Slug] = @Slug
					,[AttachedPath] = @AttachedPath
				WHERE
[PageID] = @OriginalPageId 
AND [LanguageID] = @OriginalLanguageId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbPage table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_Delete
(

	@PageId uniqueidentifier   ,

	@LanguageId int   
)
AS


				DELETE FROM [dbo].[hrbPage] WITH (ROWLOCK) 
				WHERE
					[PageID] = @PageId
					AND [LanguageID] = @LanguageId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_GetByLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_GetByLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_GetByLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPage table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_GetByLanguageId
(

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[PageID],
					[Title],
					[Description],
					[PageContent],
					[Keywords],
					[DateCreated],
					[DateModified],
					[IsPublished],
					[LanguageID],
					[ParentID],
					[Slug],
					[AttachedPath]
				FROM
					[dbo].[hrbPage]
				WHERE
					[LanguageID] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_GetByPageIdLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_GetByPageIdLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_GetByPageIdLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPage table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_GetByPageIdLanguageId
(

	@PageId uniqueidentifier   ,

	@LanguageId int   
)
AS


				SELECT
					[PageID],
					[Title],
					[Description],
					[PageContent],
					[Keywords],
					[DateCreated],
					[DateModified],
					[IsPublished],
					[LanguageID],
					[ParentID],
					[Slug],
					[AttachedPath]
				FROM
					[dbo].[hrbPage]
				WHERE
					[PageID] = @PageId
					AND [LanguageID] = @LanguageId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPage_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPage_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPage_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbPage table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPage_Find
(

	@SearchUsingOR bit   = null ,

	@PageId uniqueidentifier   = null ,

	@Title nvarchar (255)  = null ,

	@Description nvarchar (1000)  = null ,

	@PageContent nvarchar (MAX)  = null ,

	@Keywords nvarchar (4000)  = null ,

	@DateCreated datetime   = null ,

	@DateModified datetime   = null ,

	@IsPublished bit   = null ,

	@LanguageId int   = null ,

	@ParentId uniqueidentifier   = null ,

	@Slug nvarchar (255)  = null ,

	@AttachedPath nvarchar (1000)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [PageID]
	, [Title]
	, [Description]
	, [PageContent]
	, [Keywords]
	, [DateCreated]
	, [DateModified]
	, [IsPublished]
	, [LanguageID]
	, [ParentID]
	, [Slug]
	, [AttachedPath]
    FROM
	[dbo].[hrbPage]
    WHERE 
	 ([PageID] = @PageId OR @PageId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([PageContent] = @PageContent OR @PageContent IS NULL)
	AND ([Keywords] = @Keywords OR @Keywords IS NULL)
	AND ([DateCreated] = @DateCreated OR @DateCreated IS NULL)
	AND ([DateModified] = @DateModified OR @DateModified IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
	AND ([ParentID] = @ParentId OR @ParentId IS NULL)
	AND ([Slug] = @Slug OR @Slug IS NULL)
	AND ([AttachedPath] = @AttachedPath OR @AttachedPath IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [PageID]
	, [Title]
	, [Description]
	, [PageContent]
	, [Keywords]
	, [DateCreated]
	, [DateModified]
	, [IsPublished]
	, [LanguageID]
	, [ParentID]
	, [Slug]
	, [AttachedPath]
    FROM
	[dbo].[hrbPage]
    WHERE 
	 ([PageID] = @PageId AND @PageId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([PageContent] = @PageContent AND @PageContent is not null)
	OR ([Keywords] = @Keywords AND @Keywords is not null)
	OR ([DateCreated] = @DateCreated AND @DateCreated is not null)
	OR ([DateModified] = @DateModified AND @DateModified is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([LanguageID] = @LanguageId AND @LanguageId is not null)
	OR ([ParentID] = @ParentId AND @ParentId is not null)
	OR ([Slug] = @Slug AND @Slug is not null)
	OR ([AttachedPath] = @AttachedPath AND @AttachedPath is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbPostCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_Get_List

AS


				
				SELECT
					[PostCategoryID],
					[PostID],
					[CategoryID],
					[LanguageID]
				FROM
					[dbo].[hrbPostCategory]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbPostCategory table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[PostCategoryID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [PostCategoryID]'
				SET @SQL = @SQL + ', [PostID]'
				SET @SQL = @SQL + ', [CategoryID]'
				SET @SQL = @SQL + ', [LanguageID]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPostCategory]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [PostCategoryID],'
				SET @SQL = @SQL + ' [PostID],'
				SET @SQL = @SQL + ' [CategoryID],'
				SET @SQL = @SQL + ' [LanguageID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPostCategory]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbPostCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_Insert
(

	@PostCategoryId int    OUTPUT,

	@PostId uniqueidentifier   ,

	@CategoryId uniqueidentifier   ,

	@LanguageId int   
)
AS


				
				INSERT INTO [dbo].[hrbPostCategory]
					(
					[PostID]
					,[CategoryID]
					,[LanguageID]
					)
				VALUES
					(
					@PostId
					,@CategoryId
					,@LanguageId
					)
				
				-- Get the identity value
				SET @PostCategoryId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbPostCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_Update
(

	@PostCategoryId int   ,

	@PostId uniqueidentifier   ,

	@CategoryId uniqueidentifier   ,

	@LanguageId int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbPostCategory]
				SET
					[PostID] = @PostId
					,[CategoryID] = @CategoryId
					,[LanguageID] = @LanguageId
				WHERE
[PostCategoryID] = @PostCategoryId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbPostCategory table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_Delete
(

	@PostCategoryId int   
)
AS


				DELETE FROM [dbo].[hrbPostCategory] WITH (ROWLOCK) 
				WHERE
					[PostCategoryID] = @PostCategoryId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_GetByPostId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_GetByPostId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_GetByPostId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPostCategory table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_GetByPostId
(

	@PostId uniqueidentifier   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[PostCategoryID],
					[PostID],
					[CategoryID],
					[LanguageID]
				FROM
					[dbo].[hrbPostCategory]
				WHERE
					[PostID] = @PostId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_GetByCategoryIdLanguageId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_GetByCategoryIdLanguageId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_GetByCategoryIdLanguageId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPostCategory table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_GetByCategoryIdLanguageId
(

	@CategoryId uniqueidentifier   ,

	@LanguageId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[PostCategoryID],
					[PostID],
					[CategoryID],
					[LanguageID]
				FROM
					[dbo].[hrbPostCategory]
				WHERE
					[CategoryID] = @CategoryId
					AND [LanguageID] = @LanguageId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_GetByPostCategoryId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_GetByPostCategoryId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_GetByPostCategoryId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPostCategory table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_GetByPostCategoryId
(

	@PostCategoryId int   
)
AS


				SELECT
					[PostCategoryID],
					[PostID],
					[CategoryID],
					[LanguageID]
				FROM
					[dbo].[hrbPostCategory]
				WHERE
					[PostCategoryID] = @PostCategoryId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostCategory_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostCategory_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostCategory_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbPostCategory table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostCategory_Find
(

	@SearchUsingOR bit   = null ,

	@PostCategoryId int   = null ,

	@PostId uniqueidentifier   = null ,

	@CategoryId uniqueidentifier   = null ,

	@LanguageId int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [PostCategoryID]
	, [PostID]
	, [CategoryID]
	, [LanguageID]
    FROM
	[dbo].[hrbPostCategory]
    WHERE 
	 ([PostCategoryID] = @PostCategoryId OR @PostCategoryId IS NULL)
	AND ([PostID] = @PostId OR @PostId IS NULL)
	AND ([CategoryID] = @CategoryId OR @CategoryId IS NULL)
	AND ([LanguageID] = @LanguageId OR @LanguageId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [PostCategoryID]
	, [PostID]
	, [CategoryID]
	, [LanguageID]
    FROM
	[dbo].[hrbPostCategory]
    WHERE 
	 ([PostCategoryID] = @PostCategoryId AND @PostCategoryId is not null)
	OR ([PostID] = @PostId AND @PostId is not null)
	OR ([CategoryID] = @CategoryId AND @CategoryId is not null)
	OR ([LanguageID] = @LanguageId AND @LanguageId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbPostComment table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_Get_List

AS


				
				SELECT
					[PostCommentID],
					[PostID],
					[ParentCommentID],
					[CommentDate],
					[Author],
					[Email],
					[Comment],
					[Ip],
					[IsApproved],
					[Title],
					[Phone],
					[Address]
				FROM
					[dbo].[hrbPostComment]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbPostComment table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[PostCommentID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [PostCommentID]'
				SET @SQL = @SQL + ', [PostID]'
				SET @SQL = @SQL + ', [ParentCommentID]'
				SET @SQL = @SQL + ', [CommentDate]'
				SET @SQL = @SQL + ', [Author]'
				SET @SQL = @SQL + ', [Email]'
				SET @SQL = @SQL + ', [Comment]'
				SET @SQL = @SQL + ', [Ip]'
				SET @SQL = @SQL + ', [IsApproved]'
				SET @SQL = @SQL + ', [Title]'
				SET @SQL = @SQL + ', [Phone]'
				SET @SQL = @SQL + ', [Address]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPostComment]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [PostCommentID],'
				SET @SQL = @SQL + ' [PostID],'
				SET @SQL = @SQL + ' [ParentCommentID],'
				SET @SQL = @SQL + ' [CommentDate],'
				SET @SQL = @SQL + ' [Author],'
				SET @SQL = @SQL + ' [Email],'
				SET @SQL = @SQL + ' [Comment],'
				SET @SQL = @SQL + ' [Ip],'
				SET @SQL = @SQL + ' [IsApproved],'
				SET @SQL = @SQL + ' [Title],'
				SET @SQL = @SQL + ' [Phone],'
				SET @SQL = @SQL + ' [Address]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbPostComment]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbPostComment table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_Insert
(

	@PostCommentId uniqueidentifier   ,

	@PostId uniqueidentifier   ,

	@ParentCommentId uniqueidentifier   ,

	@CommentDate datetime   ,

	@Author nvarchar (255)  ,

	@Email nvarchar (255)  ,

	@Comment nvarchar (4000)  ,

	@Ip nvarchar (50)  ,

	@IsApproved bit   ,

	@Title nvarchar (50)  ,

	@Phone nvarchar (50)  ,

	@Address nvarchar (100)  
)
AS


				
				INSERT INTO [dbo].[hrbPostComment]
					(
					[PostCommentID]
					,[PostID]
					,[ParentCommentID]
					,[CommentDate]
					,[Author]
					,[Email]
					,[Comment]
					,[Ip]
					,[IsApproved]
					,[Title]
					,[Phone]
					,[Address]
					)
				VALUES
					(
					@PostCommentId
					,@PostId
					,@ParentCommentId
					,@CommentDate
					,@Author
					,@Email
					,@Comment
					,@Ip
					,@IsApproved
					,@Title
					,@Phone
					,@Address
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbPostComment table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_Update
(

	@PostCommentId uniqueidentifier   ,

	@OriginalPostCommentId uniqueidentifier   ,

	@PostId uniqueidentifier   ,

	@ParentCommentId uniqueidentifier   ,

	@CommentDate datetime   ,

	@Author nvarchar (255)  ,

	@Email nvarchar (255)  ,

	@Comment nvarchar (4000)  ,

	@Ip nvarchar (50)  ,

	@IsApproved bit   ,

	@Title nvarchar (50)  ,

	@Phone nvarchar (50)  ,

	@Address nvarchar (100)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbPostComment]
				SET
					[PostCommentID] = @PostCommentId
					,[PostID] = @PostId
					,[ParentCommentID] = @ParentCommentId
					,[CommentDate] = @CommentDate
					,[Author] = @Author
					,[Email] = @Email
					,[Comment] = @Comment
					,[Ip] = @Ip
					,[IsApproved] = @IsApproved
					,[Title] = @Title
					,[Phone] = @Phone
					,[Address] = @Address
				WHERE
[PostCommentID] = @OriginalPostCommentId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbPostComment table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_Delete
(

	@PostCommentId uniqueidentifier   
)
AS


				DELETE FROM [dbo].[hrbPostComment] WITH (ROWLOCK) 
				WHERE
					[PostCommentID] = @PostCommentId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_GetByPostId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_GetByPostId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_GetByPostId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPostComment table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_GetByPostId
(

	@PostId uniqueidentifier   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[PostCommentID],
					[PostID],
					[ParentCommentID],
					[CommentDate],
					[Author],
					[Email],
					[Comment],
					[Ip],
					[IsApproved],
					[Title],
					[Phone],
					[Address]
				FROM
					[dbo].[hrbPostComment]
				WHERE
					[PostID] = @PostId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_GetByPostCommentId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_GetByPostCommentId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_GetByPostCommentId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbPostComment table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_GetByPostCommentId
(

	@PostCommentId uniqueidentifier   
)
AS


				SELECT
					[PostCommentID],
					[PostID],
					[ParentCommentID],
					[CommentDate],
					[Author],
					[Email],
					[Comment],
					[Ip],
					[IsApproved],
					[Title],
					[Phone],
					[Address]
				FROM
					[dbo].[hrbPostComment]
				WHERE
					[PostCommentID] = @PostCommentId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbPostComment_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbPostComment_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbPostComment_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbPostComment table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbPostComment_Find
(

	@SearchUsingOR bit   = null ,

	@PostCommentId uniqueidentifier   = null ,

	@PostId uniqueidentifier   = null ,

	@ParentCommentId uniqueidentifier   = null ,

	@CommentDate datetime   = null ,

	@Author nvarchar (255)  = null ,

	@Email nvarchar (255)  = null ,

	@Comment nvarchar (4000)  = null ,

	@Ip nvarchar (50)  = null ,

	@IsApproved bit   = null ,

	@Title nvarchar (50)  = null ,

	@Phone nvarchar (50)  = null ,

	@Address nvarchar (100)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [PostCommentID]
	, [PostID]
	, [ParentCommentID]
	, [CommentDate]
	, [Author]
	, [Email]
	, [Comment]
	, [Ip]
	, [IsApproved]
	, [Title]
	, [Phone]
	, [Address]
    FROM
	[dbo].[hrbPostComment]
    WHERE 
	 ([PostCommentID] = @PostCommentId OR @PostCommentId IS NULL)
	AND ([PostID] = @PostId OR @PostId IS NULL)
	AND ([ParentCommentID] = @ParentCommentId OR @ParentCommentId IS NULL)
	AND ([CommentDate] = @CommentDate OR @CommentDate IS NULL)
	AND ([Author] = @Author OR @Author IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Comment] = @Comment OR @Comment IS NULL)
	AND ([Ip] = @Ip OR @Ip IS NULL)
	AND ([IsApproved] = @IsApproved OR @IsApproved IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Phone] = @Phone OR @Phone IS NULL)
	AND ([Address] = @Address OR @Address IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [PostCommentID]
	, [PostID]
	, [ParentCommentID]
	, [CommentDate]
	, [Author]
	, [Email]
	, [Comment]
	, [Ip]
	, [IsApproved]
	, [Title]
	, [Phone]
	, [Address]
    FROM
	[dbo].[hrbPostComment]
    WHERE 
	 ([PostCommentID] = @PostCommentId AND @PostCommentId is not null)
	OR ([PostID] = @PostId AND @PostId is not null)
	OR ([ParentCommentID] = @ParentCommentId AND @ParentCommentId is not null)
	OR ([CommentDate] = @CommentDate AND @CommentDate is not null)
	OR ([Author] = @Author AND @Author is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Comment] = @Comment AND @Comment is not null)
	OR ([Ip] = @Ip AND @Ip is not null)
	OR ([IsApproved] = @IsApproved AND @IsApproved is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Phone] = @Phone AND @Phone is not null)
	OR ([Address] = @Address AND @Address is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_Get_List

AS


				
				SELECT
					[RoleID],
					[Role]
				FROM
					[dbo].[hrbRoles]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbRoles table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[RoleID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [RoleID]'
				SET @SQL = @SQL + ', [Role]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbRoles]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [RoleID],'
				SET @SQL = @SQL + ' [Role]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbRoles]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_Insert
(

	@RoleId int    OUTPUT,

	@Role nvarchar (100)  
)
AS


				
				INSERT INTO [dbo].[hrbRoles]
					(
					[Role]
					)
				VALUES
					(
					@Role
					)
				
				-- Get the identity value
				SET @RoleId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_Update
(

	@RoleId int   ,

	@Role nvarchar (100)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbRoles]
				SET
					[Role] = @Role
				WHERE
[RoleID] = @RoleId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_Delete
(

	@RoleId int   
)
AS


				DELETE FROM [dbo].[hrbRoles] WITH (ROWLOCK) 
				WHERE
					[RoleID] = @RoleId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_GetByRoleId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_GetByRoleId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_GetByRoleId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbRoles table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_GetByRoleId
(

	@RoleId int   
)
AS


				SELECT
					[RoleID],
					[Role]
				FROM
					[dbo].[hrbRoles]
				WHERE
					[RoleID] = @RoleId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_GetByRole procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_GetByRole') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_GetByRole
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbRoles table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_GetByRole
(

	@Role nvarchar (100)  
)
AS


				SELECT
					[RoleID],
					[Role]
				FROM
					[dbo].[hrbRoles]
				WHERE
					[Role] = @Role
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbRoles_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbRoles_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbRoles_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbRoles table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbRoles_Find
(

	@SearchUsingOR bit   = null ,

	@RoleId int   = null ,

	@Role nvarchar (100)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [RoleID]
	, [Role]
    FROM
	[dbo].[hrbRoles]
    WHERE 
	 ([RoleID] = @RoleId OR @RoleId IS NULL)
	AND ([Role] = @Role OR @Role IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [RoleID]
	, [Role]
    FROM
	[dbo].[hrbRoles]
    WHERE 
	 ([RoleID] = @RoleId AND @RoleId is not null)
	OR ([Role] = @Role AND @Role is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_Get_List

AS


				
				SELECT
					[SettingName],
					[SettingValue]
				FROM
					[dbo].[hrbSetting]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbSetting table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[SettingName]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [SettingName]'
				SET @SQL = @SQL + ', [SettingValue]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbSetting]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [SettingName],'
				SET @SQL = @SQL + ' [SettingValue]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbSetting]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_Insert
(

	@SettingName nvarchar (50)  ,

	@SettingValue nvarchar (255)  
)
AS


				
				INSERT INTO [dbo].[hrbSetting]
					(
					[SettingName]
					,[SettingValue]
					)
				VALUES
					(
					@SettingName
					,@SettingValue
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_Update
(

	@SettingName nvarchar (50)  ,

	@OriginalSettingName nvarchar (50)  ,

	@SettingValue nvarchar (255)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbSetting]
				SET
					[SettingName] = @SettingName
					,[SettingValue] = @SettingValue
				WHERE
[SettingName] = @OriginalSettingName 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbSetting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_Delete
(

	@SettingName nvarchar (50)  
)
AS


				DELETE FROM [dbo].[hrbSetting] WITH (ROWLOCK) 
				WHERE
					[SettingName] = @SettingName
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_GetBySettingName procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_GetBySettingName') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_GetBySettingName
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbSetting table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_GetBySettingName
(

	@SettingName nvarchar (50)  
)
AS


				SELECT
					[SettingName],
					[SettingValue]
				FROM
					[dbo].[hrbSetting]
				WHERE
					[SettingName] = @SettingName
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbSetting_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbSetting_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbSetting_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbSetting table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbSetting_Find
(

	@SearchUsingOR bit   = null ,

	@SettingName nvarchar (50)  = null ,

	@SettingValue nvarchar (255)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [SettingName]
	, [SettingValue]
    FROM
	[dbo].[hrbSetting]
    WHERE 
	 ([SettingName] = @SettingName OR @SettingName IS NULL)
	AND ([SettingValue] = @SettingValue OR @SettingValue IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [SettingName]
	, [SettingValue]
    FROM
	[dbo].[hrbSetting]
    WHERE 
	 ([SettingName] = @SettingName AND @SettingName is not null)
	OR ([SettingValue] = @SettingValue AND @SettingValue is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbUsers table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_Get_List

AS


				
				SELECT
					[UserID],
					[UserName],
					[Password],
					[LastLoginTime],
					[EmailAddress]
				FROM
					[dbo].[hrbUsers]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbUsers table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[UserID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [UserID]'
				SET @SQL = @SQL + ', [UserName]'
				SET @SQL = @SQL + ', [Password]'
				SET @SQL = @SQL + ', [LastLoginTime]'
				SET @SQL = @SQL + ', [EmailAddress]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbUsers]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [UserID],'
				SET @SQL = @SQL + ' [UserName],'
				SET @SQL = @SQL + ' [Password],'
				SET @SQL = @SQL + ' [LastLoginTime],'
				SET @SQL = @SQL + ' [EmailAddress]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbUsers]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbUsers table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_Insert
(

	@UserId int    OUTPUT,

	@UserName nvarchar (100)  ,

	@Password nvarchar (255)  ,

	@LastLoginTime datetime   ,

	@EmailAddress nvarchar (100)  
)
AS


				
				INSERT INTO [dbo].[hrbUsers]
					(
					[UserName]
					,[Password]
					,[LastLoginTime]
					,[EmailAddress]
					)
				VALUES
					(
					@UserName
					,@Password
					,@LastLoginTime
					,@EmailAddress
					)
				
				-- Get the identity value
				SET @UserId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbUsers table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_Update
(

	@UserId int   ,

	@UserName nvarchar (100)  ,

	@Password nvarchar (255)  ,

	@LastLoginTime datetime   ,

	@EmailAddress nvarchar (100)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbUsers]
				SET
					[UserName] = @UserName
					,[Password] = @Password
					,[LastLoginTime] = @LastLoginTime
					,[EmailAddress] = @EmailAddress
				WHERE
[UserID] = @UserId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbUsers table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_Delete
(

	@UserId int   
)
AS


				DELETE FROM [dbo].[hrbUsers] WITH (ROWLOCK) 
				WHERE
					[UserID] = @UserId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_GetByUserId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_GetByUserId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_GetByUserId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbUsers table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_GetByUserId
(

	@UserId int   
)
AS


				SELECT
					[UserID],
					[UserName],
					[Password],
					[LastLoginTime],
					[EmailAddress]
				FROM
					[dbo].[hrbUsers]
				WHERE
					[UserID] = @UserId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUsers_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUsers_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUsers_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbUsers table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUsers_Find
(

	@SearchUsingOR bit   = null ,

	@UserId int   = null ,

	@UserName nvarchar (100)  = null ,

	@Password nvarchar (255)  = null ,

	@LastLoginTime datetime   = null ,

	@EmailAddress nvarchar (100)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [UserID]
	, [UserName]
	, [Password]
	, [LastLoginTime]
	, [EmailAddress]
    FROM
	[dbo].[hrbUsers]
    WHERE 
	 ([UserID] = @UserId OR @UserId IS NULL)
	AND ([UserName] = @UserName OR @UserName IS NULL)
	AND ([Password] = @Password OR @Password IS NULL)
	AND ([LastLoginTime] = @LastLoginTime OR @LastLoginTime IS NULL)
	AND ([EmailAddress] = @EmailAddress OR @EmailAddress IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [UserID]
	, [UserName]
	, [Password]
	, [LastLoginTime]
	, [EmailAddress]
    FROM
	[dbo].[hrbUsers]
    WHERE 
	 ([UserID] = @UserId AND @UserId is not null)
	OR ([UserName] = @UserName AND @UserName is not null)
	OR ([Password] = @Password AND @Password is not null)
	OR ([LastLoginTime] = @LastLoginTime AND @LastLoginTime is not null)
	OR ([EmailAddress] = @EmailAddress AND @EmailAddress is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets all records from the hrbUserRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_Get_List

AS


				
				SELECT
					[UserRoleID],
					[UserID],
					[RoleID]
				FROM
					[dbo].[hrbUserRoles]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Gets records from the hrbUserRoles table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy IS NULL OR LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[UserRoleID]'
				END

				-- SQL Server 2005 Paging
				DECLARE @SQL AS nvarchar(MAX)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [UserRoleID]'
				SET @SQL = @SQL + ', [UserID]'
				SET @SQL = @SQL + ', [RoleID]'
				SET @SQL = @SQL + ' FROM [dbo].[hrbUserRoles]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [UserRoleID],'
				SET @SQL = @SQL + ' [UserID],'
				SET @SQL = @SQL + ' [RoleID]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + CONVERT(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + CONVERT(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				EXEC sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[hrbUserRoles]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Inserts a record into the hrbUserRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_Insert
(

	@UserRoleId int    OUTPUT,

	@UserId int   ,

	@RoleId int   
)
AS


				
				INSERT INTO [dbo].[hrbUserRoles]
					(
					[UserID]
					,[RoleID]
					)
				VALUES
					(
					@UserId
					,@RoleId
					)
				
				-- Get the identity value
				SET @UserRoleId = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Updates a record in the hrbUserRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_Update
(

	@UserRoleId int   ,

	@UserId int   ,

	@RoleId int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[hrbUserRoles]
				SET
					[UserID] = @UserId
					,[RoleID] = @RoleId
				WHERE
[UserRoleID] = @UserRoleId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Deletes a record in the hrbUserRoles table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_Delete
(

	@UserRoleId int   
)
AS


				DELETE FROM [dbo].[hrbUserRoles] WITH (ROWLOCK) 
				WHERE
					[UserRoleID] = @UserRoleId
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_GetByRoleId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_GetByRoleId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_GetByRoleId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbUserRoles table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_GetByRoleId
(

	@RoleId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[UserRoleID],
					[UserID],
					[RoleID]
				FROM
					[dbo].[hrbUserRoles]
				WHERE
					[RoleID] = @RoleId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_GetByUserId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_GetByUserId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_GetByUserId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbUserRoles table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_GetByUserId
(

	@UserId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[UserRoleID],
					[UserID],
					[RoleID]
				FROM
					[dbo].[hrbUserRoles]
				WHERE
					[UserID] = @UserId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_GetByUserRoleId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_GetByUserRoleId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_GetByUserRoleId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Select records from the hrbUserRoles table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_GetByUserRoleId
(

	@UserRoleId int   
)
AS


				SELECT
					[UserRoleID],
					[UserID],
					[RoleID]
				FROM
					[dbo].[hrbUserRoles]
				WHERE
					[UserRoleID] = @UserRoleId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.hrbUserRoles_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.hrbUserRoles_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.hrbUserRoles_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: FreeLancer ()
-- Purpose: Finds records in the hrbUserRoles table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.hrbUserRoles_Find
(

	@SearchUsingOR bit   = null ,

	@UserRoleId int   = null ,

	@UserId int   = null ,

	@RoleId int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [UserRoleID]
	, [UserID]
	, [RoleID]
    FROM
	[dbo].[hrbUserRoles]
    WHERE 
	 ([UserRoleID] = @UserRoleId OR @UserRoleId IS NULL)
	AND ([UserID] = @UserId OR @UserId IS NULL)
	AND ([RoleID] = @RoleId OR @RoleId IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [UserRoleID]
	, [UserID]
	, [RoleID]
    FROM
	[dbo].[hrbUserRoles]
    WHERE 
	 ([UserRoleID] = @UserRoleId AND @UserRoleId is not null)
	OR ([UserID] = @UserId AND @UserId is not null)
	OR ([RoleID] = @RoleId AND @RoleId is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

